package com.dily.study.demo.thread;

/**
 * Date: 2022-08-09 星期二
 * Time: 16:05
 * Author: Dily_Su
 * Remark:
 * 继承 Thread 重写 run() 实现线程创建
 * 调用 start() 方法启动线程
 *
 * 线程开启后不一定立即执行，需要等待 CPU 进行调度
 */
public class TestThread extends Thread{

    @Override
    public void run() {
        for (int i = 0; i<20; i++){
            System.out.println(Thread.currentThread().getName()+"我在学习多线程：" + i);
        }
    }


    public static void main(String[] args) {
        // 创建线程
        TestThread testThread1 = new TestThread();
        TestThread testThread2 = new TestThread();
        TestThread testThread3 = new TestThread();
        TestThread testThread4 = new TestThread();
        // 启动线程
        testThread1.start();

        testThread2.setPriority(1);
        testThread2.start();

        testThread3.setPriority(5);
        testThread3.start();

        testThread4.setPriority(10);
        testThread4.start();
    }
}